package com.jz.community.moduleshoppingguide.home.presenter;

import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.moduleshoppingguide.home.bean.ChunnelNewbornBean;
import com.jz.community.moduleshoppingguide.home.bean.HomeFindBean;
import com.jz.community.moduleshoppingguide.home.bean.HomeRecommendBean;
import com.jz.community.moduleshoppingguide.home.bean.LimitGoodsBean;
import com.jz.community.moduleshoppingguide.home.bean.QueryCouponState;
import com.jz.community.moduleshoppingguide.home.model.ShoppingGuideModel;
import com.jz.community.moduleshoppingguide.home.model.ShoppingModelGuideImpl;
import com.jz.community.moduleshoppingguide.home.ui.HomeFindView;

import java.util.List;

/**
 * Created by Tony.Fan on 2018/3/13 10:42
 */
public class HomeFindPresenter extends BaseLifeCyclePresent<HomeFindView.View> implements HomeFindView.Presenter {

    private ShoppingGuideModel shoppingModel;
    private HomeFindView.View mView;

    public HomeFindPresenter(HomeFindView.View v) {
        mView = v;
        shoppingModel = new ShoppingModelGuideImpl(v.getContext());
    }

    @Override
    public void setPresenter(HomeFindView.View v) {
        super.setPresenter(v);
    }

    @Override
    public void getChunnelHomePage(int page, int size, String cityCode) {
        shoppingModel.getChunnelHomePage(page, size, cityCode, new OnLoadListener<HomeFindBean>() {
            @Override
            public void onSuccess(HomeFindBean homeFindBean) {
                mView.showHomeChannel(homeFindBean);
            }

            @Override
            public void onFail(String s, int code) {
                mView.showError(s, 0, -1);
            }
        });
    }

    @Override
    public void getHomeRecommend(int page, int size, int refreshFlag) {
        shoppingModel.getHomeRecommend(page, size, new OnLoadListener<HomeRecommendBean>() {
            @Override
            public void onSuccess(HomeRecommendBean homeRecommendBean) {
                mView.showHomeRecommend(homeRecommendBean, refreshFlag);
            }

            @Override
            public void onFail(String s, int code) {
                mView.showError(s, 1, refreshFlag);
            }
        });
    }

    @Override
    public void getChunnelNewborn(int page, int size) {
        shoppingModel.getChunnelNewborn(page, size, new OnLoadListener<ChunnelNewbornBean>() {
            @Override
            public void onSuccess(ChunnelNewbornBean chunnelNewbornBean) {
                mView.showChunnelNewborn(chunnelNewbornBean);
            }

            @Override
            public void onFail(String s, int code) {
                mView.showError(s, 2, -1);
            }
        });
    }


    @Override
    public void initGoodsData(String cityId, String startTime, String endTime, int page, int size) {
        shoppingModel.initGoodsData(cityId, startTime, endTime, page, size, new OnLoadListener<LimitGoodsBean>() {
            @Override
            public void onSuccess(LimitGoodsBean limitGoodsBean) {
                mView.setGoodsData(limitGoodsBean, startTime, endTime);
            }

            @Override
            public void onFail(String msg, int code) {
                mView.showError(msg, 4, -1);
            }
        });
    }
}
